import matplotlib.pyplot as plt
import pandas as pd
#用来正常显示中文标签
plt.rcParams['font.sans-serif'] = ['SimHei']
#用来正常显示负号
plt.rcParams['axes.unicode_minus'] = False
df =pd.read_excel("beijing.xlsx")
print(df.head(10))
df.sort_values(by="unit_price",inplace=True)
unit_price = df['unit_price'].to_list()
total_price = df['total_price'].to_list()
area  = df['area'].to_list()
fig = plt.figure(figsize=(12,7))
ax = fig.add_subplot(111)
df.plot(x="area",y="unit_price",kind="scatter",grid=True,fontsize=12,ax=ax,alpha=0.4,xticks=[0,20,40,60,80,120,140,160,180,200,300,400,500],xlim=[0,800])
ax.set_xlabel("建筑面积(㎡)",fontsize=14)
ax.set_ylabel("单价(元/平米)",fontsize=14)
plt.show()

fig = plt.figure(figsize=(12,7))
ax = fig.add_subplot(111)
df.plot(x="area",y="total_price",kind="scatter",grid=True,fontsize=12,ax=ax,alpha=0.4,xticks=[0,20,40,60,80,120,140,160,180,200,300,400,500],xlim=[0,800])
ax.set_xlabel("建筑面积(㎡)",fontsize=14)
ax.set_ylabel("总价(万元)",fontsize=14)
plt.show()